package cn.springcloud.fix.server.api.log.feign.factory;

import cn.springcloud.fix.common.core.base.R;
import cn.springcloud.fix.server.api.log.feign.RemoteLogService;
import cn.springcloud.fix.server.api.log.request.SysLoginLogRequest;
import cn.springcloud.fix.server.api.log.request.SysOperateLogRequest;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class RemoteLogFallbackFactory implements FallbackFactory<RemoteLogService> {

    @Override
    public RemoteLogService create(Throwable throwable) {
        log.error(throwable.getMessage(), throwable);
        return new RemoteLogService() {
            @Override
            public R<Object> insertOpLog(SysOperateLogRequest request) {
                return R.ERROR("服务降级！");
            }

            @Override
            public R<Object> insertLoginLog(SysLoginLogRequest request) {
                return R.ERROR("服务降级！");
            }
        };
    }
}
